/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jebert.javamessage.control;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author jebert
 */
public class Translator {

    private Language from = Language.ENGLISH;
    private Language to;

    public Translator(Language to) {
        Translate.setHttpReferrer("ar.com.jebert");
        this.to = to;
    }

    public void setLanguage(Language lan) {
        this.to = lan;
    }

    public String translateIt(String toTranslate) {

        String translated = new String();

        try {
            translated = Translate.execute(toTranslate, from, to);
        } catch (Exception e) {
            e.printStackTrace();
            translated = toTranslate;

        }
        return translated;
    }

        public String translateToSend(String toTranslate) {

        String translated = new String();

        try {
            translated = Translate.execute(toTranslate, to,from);
        } catch (Exception e) {
            e.printStackTrace();
            translated = toTranslate;

        }
        return translated;
    }
    
    public void loadLanguages(DefaultComboBoxModel dfault) {
        for (Language lan : Language.values()) {
            if (lan.equals(Language.ENGLISH)
                    | lan.equals(Language.SPANISH)
                    | lan.equals(Language.PORTUGUESE)
                    | lan.equals(Language.FRENCH)
                    | lan.equals(Language.GERMAN)
                    | lan.equals(Language.GREEK)
                    | lan.equals(Language.CATALAN)
                    | lan.equals(Language.ITALIAN)) {
                dfault.addElement(lan.name());
            }

        }
    }
}
